import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
from app.core.config import settings

async def list_users():
    try:
        client = AsyncIOMotorClient(settings.MONGODB_URL)
        db = client[settings.MONGODB_DATABASE]
        
        print('数据库中的所有用户:')
        users = await db.users.find({}, {'username': 1, 'name': 1, 'email': 1}).to_list(None)
        if users:
            for user in users:
                print(f'用户名: {user.get("username")}, 姓名: {user.get("name")}, 邮箱: {user.get("email")}')
        else:
            print('数据库中没有用户')
        
        client.close()
    except Exception as e:
        print(f'错误: {e}')
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(list_users())